The Internet Control Pack includes several controls which allow you to connect to external servers (the Internet) and download files. In some cases, the files may be large, and take a minute or longer to download. The data stream that returns from the Internet is aysnchronousùdata arrives in "packets," instead of a single stream. To handle the asynchronous data stream, the following OLE objects have been created:
- DocHeader Object
- DocInput Object
- DocOutput Object
- icErrors Object
Data streams: data, DocHeaders, and icErrors
The DocInput and DocOutput objects serve as routers of incoming and outgoing data streams. Whenever a control streams data, you can use the DocInput or DocOutput object to parse the data and assign the data stream to one of several destinations:
- Dataùdata that can be passed to a container (such as a TextBox control) or a file
- DocHeaders collectionùHeader information that varies from control to control. For example, a collection of NNTP DocHeader objects would contain subject, destination, and newsgroup
- icErrors collectionùif an error occurs on the netword that is sending the data, information about the error can be stored in an icError object
Scenario: Using the DocInput object to retrieve an NNTP document
A common task is to download messages from a remote news server. The steps to downloading a message using the DocOutput object are as follows:
- The NNTP control invokes a GetArticleByArticleNumber method.
- The remote server responds by sending the article in data packets.
- On the client computer, the DocInput event is triggered as each data packet arrives.
- The DocInput passes a reference to aDocInput object.
- The DocInput object includes a State property which indicates the state of the data stream.
- Depending on the value of the State property, incoming data is passed either into a data variable, an icError object, or a DocHeader object.
- Presuming no errors have occurred, use the GetData method of the DocObject to pass the data into a container or a file.
The following code shows this process:
Private SubGetArticleByNumber_Click()
' Presuming an NNTP control exists by the name of
' of "nntp1".
' txtArticleNum is a TextBox control containign the
' required parameter.
nntp1.GetArticleByArticleNumber txtArticleNum
End Sub
Private nntp1_DocInput(DocInput As DocInput)
Dim vtData ' Variable for data.
Select Case DocInput.State
Case icDocNone ' No transfer in progress.
Exit Sub
Case icDocBegin ' Transer is being initiated.
' Open a file for input
Case icDocHeaders ' Document headers are being
' transferred.
' Add the Header to the DocHeaders collection.
Case icDocData ' One block of data is
' transferred.
' Use the Getdata Method to retrieve the data
DocInput.GetData vtData
Case icError
' If it's an error, use the icErrors collection.
MsgBox icErrors.Description
End Case
End Sub
The previous code demonstrates the basics of getting data from a control that uses the DocInput or DocOutput objects. In simple terms, the DocOutput is used to stream data out the machine, and the DocInput object is used to process incoming data.
|